<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>用户界面</title>
    <link rel="shortcut icon" th:href="@{/logo/favicon.ico}"/>
    <!-- Custom fonts for this template-->
    <link rel="stylesheet" type="text/css" th:href="@{/vendor/fontawesome-free/css/all.min.css}"/>
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
          rel="stylesheet">
    <!-- Custom styles for this template-->
    <link rel="stylesheet" type="text/css" th:href="@{/css/sb-admin-2.min.css}"/>
    <!-- Custom styles for this page -->
    <link rel="stylesheet" type="text/css" th:href="@{/vendor/datatables/dataTables.bootstrap4.min.css}"/>

</head>
<style>
    td {
        border: 1px solid black;
    }

    #table_one td {
        border-top: 1px solid black;
    }

    [contenteditable="false"], [contenteditable="true"] {
        color: black;
        font-weight: bold;
    }

    .table th, .table td {
        text-align: center;
        vertical-align: middle !important;
    }

    div img {
        width: 50%;
    }
</style>
<body id="page-top">

<!-- Page Wrapper -->
<div id="wrapper">
    <!-- Sidebar -->
    <div th:replace="commons/user_sidebar::#accordionSidebar"></div>
    <!-- End of Sidebar -->
    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">
        <!-- Main Content -->
        <div id="content">
            <!-- Topbar -->
            <div th:replace="commons/user_navbar::#navbar"></div>
            <div th:replace="commons/modify_report_modal2::#report2_modal"></div>
            <div class="modal fade" id="report_error_info" >
                <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                        <!-- 模态框头部 -->
                        <div class="modal-header">
                            <h4 class="modal-title">驳回原因</h4>
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                        </div>
                        <!-- 模态框主体 -->
                        <div class="modal-body">
                            <span style="color: red" id="error_content"></span>
                        </div>
                        <!-- 模态框底部 -->
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Begin Page Content -->
            <div class="container-fluid">
                <!-- DataTales Example -->
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary" style="text-align: center">审核报告进度</h6>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover text-nowrap" id="dataTable" cellspacing="0">
                                <thead>
                                <tr>
                                    <th>报告id</th>
                                    <th>报告编号</th>
                                    <th>委托单位</th>
                                    <th>检测类别</th>
                                    <th>检测时间</th>
                                    <th>提交时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- End of Main Content -->
        <!-- Footer -->
        <div th:replace="commons/footer::#footer"></div>
        <!-- End of Footer -->

    </div>
    <!-- End of Content Wrapper -->

</div>
<!-- End of Page Wrapper -->

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>

<!-- Logout Modal-->
<div th:replace="commons/logout::#logoutModal"></div>

<!-- Bootstrap core JavaScript-->
<script type="text/javascript" th:src="@{/vendor/jquery/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>

<script type="text/javascript" th:src="@{/js/user_commons.js}"></script>
<!-- Core plugin JavaScript-->
<script type="text/javascript" th:src="@{/vendor/jquery-easing/jquery.easing.min.js}"></script>
<!-- Custom scripts for all pages-->

<script type="text/javascript" th:src="@{/js/sb-admin-2.min.js}"></script>

<!-- Page level plugins -->
<script type="text/javascript" th:src="@{/vendor/datatables/jquery.dataTables.min.js}"></script>
<script type="text/javascript" th:src="@{/vendor/datatables/dataTables.bootstrap4.min.js}"></script>

<script type="text/javascript" th:src="@{/js/demo/datatables-demo.js}"></script>
</body>
<script>
    var table;
    $(function () {
        //提示信息
        $.fn.dataTable.ext.errMode = 'none';
        var lang = {
            "bAutoWidth": false,
            "sProcessing": "处理中...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        //初始化表格
        table = $("#dataTable")
            .on('error.dt', function (e, settings, techNote, message) {
                console.warn(message)
            }).dataTable({
                destroy: true,
                autoWidth: false,
                language: lang, //提示信息
                stripeClasses: ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
                processing: true, //隐藏加载提示,自行处理
                serverSide: false, //启用服务器端分页
                searching: true, //禁用原生搜索
                orderMulti: true, //启用多列排序
                order: [], //取消默认排序查询,否则复选框一列会出现小箭头
                renderer: "bootstrap", //渲染样式：Bootstrap和jquery-ui
                pagingType: "simple_numbers", //分页样式：simple,simple_numbers,full,full_numbers
                columnDefs: [{
                    "targets": 'nosort', //列的样式名
                    "orderable": false //包含上样式名‘nosort'的禁止排序
                }],
                ajax: function (data, callback, settings) {
                    $.ajax({
                        type: "GET",
                        beforeSend: function (request) {
                            request.setRequestHeader("uid", localStorage.getItem("token"));
                        },
                        url: "/user/get-report2",
                        cache: false, //禁用缓存
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            returnData.data = result.data;//返回的数据列表
                            console.log(result.data);
                            callback(returnData);
                        }
                    });
                },
                "columns": [
                    {"data": "report2Id", visible: false},
                    {"data": "reportNumber"},
                    {"data": "entrustingParty"},
                    {"data": "checkCategory"},
                    {"data": "checkDate"},
                    {"data": "createTime"},
                    {
                        "data": "status",
                        render: function (data, type, full) {
                            var temp = "";
                            switch (data) {
                                case 0:
                                    temp = "已保存";
                                    break;
                                case 1:
                                    temp = "待审核";
                                    break;
                                case 2:
                                    temp = "审核中";
                                    break;
                                case 3:
                                    temp = "<a onclick='view_report2_error(" + full.report2Id + "," + data + ")' href='#' style='color: red' title='点击查看驳回原由'>不合格</a>";
                                    break;
                                case 4:
                                    temp = "<span style='color: green'>合格</span>";
                                    break;
                                case 5:
                                    temp = "<a onclick='view_report2_error(" + full.report2Id + "," + data + ")' href='#' style='color: red' title='点击查看驳回原由'>不合格</a>";
                                    break;
                                case 6:
                                    temp = "已归档";
                                    break;
                            }
                            return temp;
                        }
                    },
                    {
                        render: function (data, type, full) {
                            return "<button onclick='view_report2(" + full.report2Id + "," + full.status + ");'  class='btn btn-info btn-icon-split'> <span class='text'>查看</span></button>" +
                                "<button onclick='remove_report2(" + full.report2Id + "," + full.status + ");'  class='btn btn-warning btn-icon-split'> <span class='text'>删除</span></button>";
                        },
                    },
                ],
                "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {                    //列样式处理
                }
            })
            .api();
        //此处需调用api()方法,否则返回的是JQuery对象而不是DataTables的API对象
    });

    function view_report2_error(rid,status) {
        $.ajax({
            type: "GET",
            beforeSend: function (request) {
                request.setRequestHeader("uid", localStorage.getItem("token"));
            },
            url: "/user/report2-error-info?rid="+rid+"&status="+status,
            cache: false, //禁用缓存
            dataType: "json",
            success: function (result) {
                $("#error_content").text(result.data);
            }
        });
        $("#report_error_info").modal("show");
    }
    function remove_report2(rid, status) {
        var con = confirm("确认删除?");
        if(!con){
            return false;
        }
        if (status == 0 || status == 1 || status == 3 || status == 5) {
            $.ajax({
                type: "GET",
                beforeSend: function (request) {
                    request.setRequestHeader("uid", localStorage.getItem("token"));
                },
                url: "/user/remove-reprot2?rid=" + rid,
                success: function (result) {
                    $("#dataTable").DataTable().ajax.reload();
                }
            });
        } else {
            alert("报告无法删除---->");
        }
    }

    $("#modify_report2").click(function () {
        var data_json = JSON.stringify({
            report2Id: $("#report2Id").val().trim(),
            reportNumber: $("#reportNumber").val().trim(),
            projectName: $("#projectName").val().trim(),
            entrustingParty: $("#entrustingParty").val().trim(),
            checkCategory: $("#checkCategory").val().trim(),
            reportDate: $("#reportDate").val().trim(),
            checkOrganization: $("#checkOrganization").text().trim(),  //text
            checkItem: $("#checkItem").text().trim(),
            basisStandard: $("#basisStandard").text().trim(),
            basisNumber: $("#basisNumber").text().trim(),
            checkAddress: $("#checkAddress").val().trim(),
            checkMethod: $("#checkMethod").val().trim(),
            equipmentName: $("#equipmentName").val().trim(),
            equipmentModel: $("#equipmentModel").val().trim(),
            equipmentMeasurementCertificate: $("#equipmentMeasurementCertificate").val().trim(),
            machineName: $("#machineName").val().trim(),
            machineModel: $("#machineModel").val().trim(),
            serialNumber: $("#serialNumber").val().trim(),
            hbNumber: $("#hbNumber").val().trim(),
            machineProtectionNumber: $("#machineProtectionNumber").val().trim(),
            equipmentNumber: $("#equipmentNumber").val().trim(),
            emissionPeriod: $("#emissionPeriod").val().trim(),
            machineDate: $("#machineDate").val().trim(),
            machineVin: $("#machineVin").val().trim(),
            machineManufacturer: $("#machineManufacturer").val().trim(),
            engineModel: $("#engineModel").val().trim(),
            engineNumber: $("#engineNumber").val().trim(),
            engineManufacturer: $("#engineManufacturer").val().trim(),
            engineReprocessType: $("#engineReprocessType").val().trim(),
            engineSpeed: $("#engineSpeed").val().trim(),
            enginePower: $("#enginePower").val().trim(),
            enviProtNo: $("#enviProtNo").val().trim(),
            engineApprovalNumber: $("#engineApprovalNumber").val().trim(),
            agentName: $("#agentName").val().trim(),
            agentMobile: $("#agentMobile").val().trim(),
            agentAddress: $("#agentAddress").val().trim(),
            temperature: $("#temperature").val().trim(),
            pressure: $("#pressure").val().trim(),
            humidity: $("#humidity").val().trim(),
            elevation: $("#elevation").val().trim(),
            checkDate: $("#checkDate").val().trim(),
            checkStartEndTime: $("#checkStartEndTime").val().trim(),
            checkAvg: $("#checkAvg").val().trim(),
            checkSpeed: $("#checkSpeed").val().trim(),
            checkHighArea: $("#checkHighArea").val().trim(),
            checkLimit: $("#checkLimit").val().trim(),
            checkResult1: $("#checkResult1").val().trim(),
            checkResult2: $("#checkResult2").val().trim(),
            checkResult3: $("#checkResult3").val().trim(),
            checkVp: $("#checkVp").val().trim(),
            checkJudgment: $("#checkJudgment").val().trim(),
        });
        $.ajax({
            url:"/user/modify-report2",
            type:"POST",
            contentType: "application/json;charset=utf-8",
            beforeSend: function (request) {
                $("#loading").modal("show");
                request.setRequestHeader("uid", localStorage.getItem("token"));
            },
            data:data_json,
            dateType: "json",
            success:function (res) {
                alert(res.message);
                $("#dataTable").DataTable().ajax.reload();
            }
        });
    });

    function view_report2(rid,status) {
        if(status == 0){
            window.open("/user/get-save-report2?rid="+rid+"&status="+status+"&ten="+localStorage.getItem("token"));
            // window.location.href = "/user/get-save-report2?rid="+rid+"&status="+status+"&ten="+localStorage.getItem("token");
            return false;
        };
        if(status == 1 || status == 3 || status == 5){
            window.open("/user/get-save-report2?rid="+rid+"&status="+status+"&ten="+localStorage.getItem("token"));
            // window.location.href = "/user/get-save-report2?rid="+rid+"&status="+status+"&ten="+localStorage.getItem("token");
            return false;
        }
        $.ajax({
            type: "GET",
            url: "/user/get2?rid=" + rid,
            success: function (data) {
                var obj = data.data;
                console.log(obj.entrustingParty);
                $("#report2Id").val(obj.report2Id);
                $("#reportNumber").val(obj.reportNumber);
                $("#projectName").val(obj.projectName);
                $("#entrustingParty").val(obj.entrustingParty);
                $(".entrustingParty").text(obj.entrustingParty);
                $("#checkCategory").val(obj.checkCategory);
                $("#reportDate").val(obj.reportDate);
                $("#checkOrganization").text(obj.checkOrganization);  //text
                $("#checkItem").text(obj.checkItem);
                $("#basisStandard").text(obj.basisStandard);
                $("#basisNumber").text(obj.basisNumber);
                $("#checkAddress").val(obj.checkAddress);
                $("#checkMethod").val(obj.checkMethod);
                $("#equipmentName").val(obj.equipmentName);
                $("#equipmentModel").val(obj.equipmentModel);
                $("#equipmentMeasurementCertificate").val(obj.equipmentMeasurementCertificate);
                $("#machineName").val(obj.machineName);
                $("#machineModel").val(obj.machineModel);
                $("#serialNumber").val(obj.serialNumber);
                $("#hbNumber").val(obj.hbNumber);
                $("#machineProtectionNumber").val(obj.machineProtectionNumber);
                $("#equipmentNumber").val(obj.equipmentNumber);
                $("#emissionPeriod").val(obj.emissionPeriod);
                $("#machineDate").val(obj.machineDate);
                $("#machineVin").val(obj.machineVin);
                $("#machineManufacturer").val(obj.machineManufacturer);
                $("#engineModel").val(obj.engineModel);
                $("#engineNumber").val(obj.engineNumber);
                $("#engineManufacturer").val(obj.engineManufacturer);
                $("#engineReprocessType").val(obj.engineReprocessType);
                $("#engineSpeed").val(obj.engineSpeed);
                $("#enginePower").val(obj.enginePower);
                $("#enviProtNo").val(obj.enviProtNo);
                $("#engineApprovalNumber").val(obj.engineApprovalNumber);
                $("#agentName").val(obj.agentName);
                $("#agentMobile").val(obj.agentMobile);
                $("#agentAddress").val(obj.agentAddress);
                $("#temperature").val(obj.temperature);
                $("#pressure").val(obj.pressure);
                $("#humidity").val(obj.humidity);
                $("#elevation").val(obj.elevation);
                $("#checkDate").val(obj.checkDate);
                $(".checkDate").text(obj.checkDate);
                $("#checkStartEndTime").val(obj.checkStartEndTime);
                $("#checkAvg").val(obj.checkAvg);
                $("#checkSpeed").val(obj.checkSpeed);
                $("#checkHighArea").val(obj.checkHighArea);
                $("#checkLimit").val(obj.checkLimit);
                $("#checkResult1").val(obj.checkResult1);
                $("#checkResult2").val(obj.checkResult2);
                $("#checkResult3").val(obj.checkResult3);
                $("#checkVp").val(obj.checkVp);
                $("#checkJudgment").val(obj.checkJudgment);
                $("#pic1").attr("src",obj.pic1);
                $("#pic2").attr("src",obj.pic2);
                $("#pic3").attr("src",obj.pic3);
                $("#pic4").attr("src",obj.pic4);
                $("#pic5").attr("src",obj.pic5);
                $("#pic6").attr("src",obj.pic6);
                $("#pic7").attr("src",obj.pic7);
                $("#pic8").attr("src",obj.pic8);
                $("#pic9").attr("src",obj.pic9);
                $("#pic10").attr("src",obj.pic10);
            }
        });
        $("#report2_modal").modal("show");
    }


</script>
<script>
    //数据写入时变化
    $("#reportNumber").bind("input propertychange", function () {
        $(".report_number").html($(this).val());
    });
    $("#entrustingParty").bind("input propertychange", function () {
        $(".entrustingParty").html($(this).val());
    });
    $("#checkDate").bind("input propertychange", function () {
        $(".checkDate").html($(this).val());
    });

    //页码变化 , 内容切换
    var count = 1;
    $(".pagination li").eq(0).click(function () {
        if (count <= 1) {
            $(".pagination li").eq(0).addClass("disabled");
            return false;
        } else {
            $(".pagination li").eq(6).removeClass("disabled");
            $(".pagination li").eq(count).removeClass("active");
            $("#content_" + count).css("display", "none");
            --count;
            $(".pagination li").eq(count).addClass("active");
            $("#content_" + count).css("display", "block");
        }
        if (count == 1) {
            $(".pagination li").eq(0).addClass("disabled");
        }
    });
    $(".pagination li").eq(6).click(function () {
        if (count >= 5) {
            $(".pagination li").eq(6).addClass("disabled");
            return false;
        }
        $(".pagination li").eq(0).removeClass("disabled");
        $(".pagination li").eq(count).removeClass("active");
        $("#content_" + count).css("display", "none");
        ++count;
        $(".pagination li").eq(count).addClass("active");
        $("#content_" + count).css("display", "block");
        if (count == 5) {
            $(".pagination li").eq(6).addClass("disabled");
        }
    })
    $(".pagination li").eq(1).click(function () {
        $(".pagination li").eq(6).removeClass("disabled");
        $(".pagination li").eq(0).addClass("disabled");
        $(".pagination li").eq(1).addClass("active");
        $(".pagination li").eq(count).removeClass("active");
        $("#content_" + count).css("display", "none");
        $("#content_" + 1).css("display", "block");
        count = 1;
    });
    $(".pagination li").eq(5).click(function () {
        $(".pagination li").eq(0).removeClass("disabled");
        $(".pagination li").eq(6).addClass("disabled");
        $(".pagination li").eq(5).addClass("active");
        $(".pagination li").eq(count).removeClass("active");
        $("#content_" + count).css("display", "none");
        $("#content_" + 5).css("display", "block");
        count = 5;
    });
    $(".pagination li").eq(2).click(function () {
        $(".pagination li").eq(0).removeClass("disabled");
        $(".pagination li").eq(6).removeClass("disabled");
        $(".pagination li").eq(count).removeClass("active");
        $(".pagination li").eq(2).addClass("active");
        $("#content_" + count).css("display", "none");
        $("#content_" + 2).css("display", "block");
        count = 2;
    });
    $(".pagination li").eq(3).click(function () {
        $(".pagination li").eq(0).removeClass("disabled");
        $(".pagination li").eq(6).removeClass("disabled");
        $(".pagination li").eq(count).removeClass("active");
        $(".pagination li").eq(3).addClass("active");
        $("#content_" + count).css("display", "none");
        $("#content_" + 3).css("display", "block");
        count = 3;
    });
    $(".pagination li").eq(4).click(function () {
        $(".pagination li").eq(0).removeClass("disabled");
        $(".pagination li").eq(6).removeClass("disabled");
        $(".pagination li").eq(count).removeClass("active");
        $(".pagination li").eq(4).addClass("active");
        $("#content_" + count).css("display", "none");
        $("#content_" + 4).css("display", "block");
        count = 4;
    });
</script>
</html>
